<?php
class ControllerModuleNewshome extends Controller
{
	public function index($setting)
	{
		
		$this->load->model('catalog/news');
        $this->load->model('catalog/category');        
        $categories=$this->model_catalog_category->getCategories();
        $category_data=array();
        foreach($categories as $category)
        {
            $news_data=array();
            $newss=$this->model_catalog_news->getLatestNewssByCatalogId($category['category_id'],10);
            
            foreach($newss as $news) {
                $news_data[]=array(
                    'title'     =>  $news['title'],
                    'summary'   =>  $news['summary'],
                    'image'     =>  HTTP_IMAGE.$news['image'],
                    'href'      =>  $this->url->link('news/news','news_id='.$news['news_id'],'') 
                );
            }
            $category_data[]=array(
                'name' =>    $category['name'],
                'href'  =>      $this->url->link('news/category','category_id='.$category['category_id']),
                'news'  =>  $news_data
            );
            
        }
        $this->data['categories']=$category_data;
        
	
		if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/module/newshome.tpl')) {
			$this->template = $this->config->get('config_template') . '/template/module/newshome.tpl';
		} else {
			$this->template = 'default/template/module/newshome.tpl';
		}
		$this->render();	
	}
}
?>